package net.qiqb.rabbitmq;

import jakarta.annotation.Resource;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;

public class RabbitmqBeanPostProcessor implements SmartInitializingSingleton {

    @Resource
    private ApplicationContext applicationContext;

    @Resource
    private RabbitAdmin rabbitAdmin;


    @Override
    public void afterSingletonsInstantiated() {
        rabbitAdmin.declareExchange(applicationContext.getBean("defaultDomainEventFanoutExchange", FanoutExchange.class));
        rabbitAdmin.declareQueue(applicationContext.getBean("defaultDomainEventQueue", Queue.class));
    }
}
